<?php

require_once 'common/conn.php';
require_once 'common/common.php';
require_once 'action/titlePacket.action.php';

$version = getParameter("version");
$os = "ios";

if ($version != "" && $os != "") {
    $db = new DBC();
    $titlePacketArray = getAllTitlePacketByOS($db, $version, $os);
    $db->close();
    echo json_encode($titlePacketArray);
} else {
    $db = new DBC();
//$sql = "SELECT name,price,goodprice,promotion,iconUrl,qstUrl,musicUrl,imageUrl,version FROM t_hibaby_title_packet WHERE os = 'ios' ORDER BY name";

    $sql = "SELECT name,price,goodprice,promotion,iconUrl,newIconUrl,qstUrl,musicUrl,imageUrl,version,iconVersion,appleId,gold,dollar,title,dollarID FROM t_hibaby_title_packet WHERE os = 'ios' ORDER BY name";
    $data = $db->fetchData($sql);
    if (checkArrayNotEmpty($data)) {
        for ($i = 0; $i < count($data); $i++) {
            if (isNull($data[$i]['gold'])) {
                $data[$i]['gold'] = "0";
            }
            if (isNull($data[$i]['dollar'])) {
                $data[$i]['dollar'] = "0";
            }
            if (isNull($data[$i]['dollarID'])) {
                $data[$i]['dollarID'] = "0";
            }
            if (isNull($data[$i]['title'])) {
                $data[$i]['title'] = "";
            }
            if (isNull($data[$i]['iconUrl'])) {
                $data[$i]['iconUrl'] = "";
            }
            if (isNull($data[$i]['newIconUrl'])) {
                $data[$i]['newIconUrl'] = "";
            }
            if (isNull($data[$i]['qstUrl'])) {
                $data[$i]['qstUrl'] = "";
            }
            if (isNull($data[$i]['musicUrl'])) {
                $data[$i]['musicUrl'] = "";
            }
            if (isNull($data[$i]['imageUrl'])) {
                $data[$i]['imageUrl'] = "";
            }
            if (isNull($data[$i]['iconVersion'])) {
                $data[$i]['iconVersion'] = "0";
            }
        }
    }
    echo json_encode($data);
}
?>